package imse.team0.customers;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * @author Eugen, 5/4/12 1:31 PM
 */
public class ClientInfoStorage {
    private static Properties clientAddresses = new Properties();
    private static Properties clientInvoiceEndpoints = new Properties();
    private static Logger LOG = LoggerFactory.getLogger(ClientInfoStorage.class.getName());

    static {
        BufferedReader br = new BufferedReader(new InputStreamReader(ClientInfoStorage.class.getResourceAsStream("/clients.properties")));
        String line;
        try {
            line = br.readLine(); // skip first line cause it is a comment
            while ((line = br.readLine()) != null) {
                String[] tokens = line.split("=");
                clientAddresses.put(tokens[0].trim(), tokens[1].trim());
                clientInvoiceEndpoints.put(tokens[0].trim(), tokens[2].trim());
            }
            br.close();
        } catch (IOException ex) {
            LOG.error("client.properties could not be read...");
            throw new RuntimeException(ex);
        }
    }

    public static String getClientAddress(String clientID){
        return clientAddresses.getProperty(clientID);
    }

    public static String getClientInvoiceEndpoint(String clientID ) {
        return clientInvoiceEndpoints.getProperty(clientID);
    }
}
